﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace X.LOG.Abstract
{
    public abstract class BaseLog<T> where T : new()
    {
        private string _LogStashServer;
        /// <summary>
        /// LOGSTASH服务器IP
        /// </summary>
        public virtual string LogStashServer
        {
            get
            {
                try
                {
                    if(string.IsNullOrEmpty(_LogStashServer))
                    {
                        _LogStashServer = System.Configuration.ConfigurationManager.AppSettings["LogStashServer"]?.Trim();
                        if (string.IsNullOrEmpty(_LogStashServer))
                            throw new Exception();
                    }
                }
                catch
                {
                    _LogStashServer = Config.DefaultLogStashServerIp;
                }
                return _LogStashServer;
            }
        }

        private int _LogStashServerPort = 0;
        /// <summary>
        /// LOGSTASH配置的HTTP端口
        /// </summary>
        public virtual int LogStashSeverPort
        {
            get
            {
                try
                {
                    if (_LogStashServerPort.Equals(0))
                    {
                        var port = System.Configuration.ConfigurationManager.AppSettings["LogStashServerPort"]?.Trim();
                        if (string.IsNullOrEmpty(port))
                            throw new Exception();
                        _LogStashServerPort = Convert.ToInt32(port);
                        if (_LogStashServerPort.Equals(0))
                            throw new Exception();
                    }
                }
                catch
                {
                    _LogStashServerPort = Config.DefaultLogStashServerPort;
                }
                
                return _LogStashServerPort;
            }
        }

        public T Body { get; set; }

    }
}
